import {
	wxPay,
} from "@/api/payment/index.js"


module.exports = {

	data() {
		return {
			timer: null,
			orderNo: null, //订单号
		}
	},
	onLoad() {

	},

	methods: {
		wxPay(option) {
			let {
				success,
				fail,
				complete,
			} = option
			wxPay({
				orderNumber: this.orderNo
			}).then(res => {
				let obj = res.data
				console.log(obj,"obj")
				uni.getProvider({
					service: 'payment',
					success: function(res) {
						// console.log(res.provider,"res.provider")
						if (~res.provider.indexOf('wxpay')) {
							uni.requestPayment({
								provider: 'wxpay',
								timeStamp: obj.timeStamp,
								nonceStr: obj.nonceStr,
								package: obj.packageValue,
								signType: obj.signType,
								paySign: obj.paySign,
								success: function(res) {
									success && success()
								},
								fail:function(err){
									console.log(err,'err')
									fail&&fail()
									complete&&complete()
								}
							});
						}
					}
				});
			})
			
		}
	},
	onUnload() {
		clearTimeout(this.timer)
	},

}
